<template>
  <div class="vip-promoters">
    <div class="top">
      <app-main-title title="推广拉新" />
      <!-- Tips-->
      <div class="top-tips app-main-tips-box">
        <div class="title">
          <i class="el-icon-warning" /> 推广说明
        </div>
        <ul>
          <li>1.您的员工或者顾客都可以是推广员，您可以通过推广类型区分。</li>
          <li>2.如果使用小程序推广的顾客手机号与您某个员工手机号一样，系统会理解为同一个推广员。</li>
          <li>
            3.如果需要查看员工提成情况，请点击查看
            <a href class="btn" @click.prevent="goStatementPromotersBonus">
              <u>员工会员推广提成报表</u>
            </a> 。
          </li>
          <li>
            4.员工在小程序上我的页面即可使用推广功能，如果需要批量制作物料二维码，请点击
            <a href class="btn" @click.prevent="handleDown">
              <u>导出员工二维码</u>
            </a> 。
          </li>
        </ul>
      </div>
    </div>

    <!-- tab -->
    <div class="tab">
      <el-tabs v-model="tabName" @tab-click="handleTabClick">
        <el-tab-pane label="推广员拉新记录" name="record">
          <promote-record ref="giveRecord" :tab-name="tabName" />
        </el-tab-pane>
        <el-tab-pane label="推广配置" name="config">
          <promote-config :tab-name="tabName" />
        </el-tab-pane>
      </el-tabs>
    </div>

    <!-- 导出 -->
    <DialogShopListTree
      ref="dialogShopListTree"
      title="导出推广码"
      :has-headquarters="true"
      @emitShopIds="emitShopIds"
    />
    <!-- <DialogShopListTree title="导出推广码" ref="dialogShopListTree" @emitShopIds="emitShopIds" /> -->
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import PromoteRecord from './components/PromoteRecord'
import PromoteConfig from './components/PromoteConfig'
import { downUserPromoteQrCode } from '@/api/download'

export default {
  components: {
    PromoteRecord,
    PromoteConfig
  },
  data() {
    return {
      tabName: 'record'
    }
  },
  mounted() {
    if (this.$route.query.type === 'config') {
      this.tabName = 'config'
    }
    this.getActiveMaIsOnline()
  },
  methods: {
    /**
       *  获取数据
       */
    // 获取小程序是否上线
    ...mapActions(['getAuthMa']),
    getActiveMaIsOnline() {
      this.getAuthMa()
    },

    /**
       *  按钮组
       */
    // 打开导出员工二维码
    handleDown() {
      if (!this.$store.state.wechat.maInfo.DEFAULT.isOnline) {
        this.$alert('商户小程序未正式发布，暂时不可以获取二维码！', '提示', {
          confirmButtonText: '确定',
          center: true,
          type: 'warning',
          callback: action => {}
        })
      } else {
        this.$refs.dialogShopListTree.open([], false, true)
      }
    },

    // 选择门店回调
    emitShopIds(ids) {
      if (ids.length === 0) {
        this.$alert('请至少选择一个门店导出', '提示', {
          confirmButtonText: '确定',
          center: true,
          type: 'warning',
          callback: action => {}
        })
      } else {
        this.$refs.dialogShopListTree.loading()
        downUserPromoteQrCode({ shopIds: ids })
          .then(res => {
            this.$alert('数据导出中，请稍后到数据下载中心进行下载', '提示', {
              confirmButtonText: '确定',
              center: true,
              type: 'success',
              callback: action => {}
            })
            this.$refs.dialogShopListTree.hide()
          })
          .finally(() => {
            this.$refs.dialogShopListTree.loading(false)
          })
      }
    },

    // 切换tab栏
    handleTabClick(tab, event) {},

    // 跳转提成报表
    goStatementPromotersBonus() {
      this.$router.push({
        name: 'StatementPromotersBonus'
      })
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
  .top {
    padding: 24px 30px;
    border-radius: 5px 5px 0 0;
    background-color: #fff;
  }
</style>
<style rel="stylesheet/scss" lang="scss">
  /* reset element*/
  .vip-promoters {
    .tab {
      .el-tabs__header {
        padding-left: 30px;
        margin-bottom: 10px;
        background-color: #fff;
        border-radius: 0 0 5px 5px;
      }
      .el-tabs__nav-wrap::after {
        background-color: #fff;
      }
      .el-tabs__active-bar {
        height: 4px;
      }
    }
  }
</style>

